package com.manor.paradise.activity

import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.ResourceUtils
import com.bumptech.glide.Glide
import com.manor.common.activity.AbsActivity
import com.manor.common.http.JHttpCallback
import com.manor.common.utils.DrawableUtil
import com.manor.common.utils.GsonUtil
import com.manor.common.utils.ToastUtil
import com.manor.paradise.R
import com.manor.paradise.adapter.VP2Adapter
import com.manor.paradise.bean.ReikInfoBean
import com.manor.paradise.fragment.ReikiIndexFragment
import com.manor.paradise.http.ElvesHttpConst
import com.manor.paradise.http.ElvesHttpUtil
import kotlinx.android.synthetic.main.activity_reik_index.*

/**
 * 我的灵气指数
 */
public class ReikiIndexActivity : AbsActivity() {
    private var mAdapter: VP2Adapter? = null


    var bHire = true
    var pageNum = 1
    override fun getLayoutId(): Int {
        return R.layout.activity_reik_index
    }

    override fun main() {
        super.main()
        im_back.setOnClickListener { finish() }
        ivQuest.setOnClickListener {
            ExplainActivity.forward(this, ExplainActivity.DESCRIPTION_OF_REIKI_INDEX)
        }

        val fragmentList: MutableList<Fragment> = mutableListOf(
                ReikiIndexFragment.newInstance(true),
                ReikiIndexFragment.newInstance(false)
        )

        mAdapter = VP2Adapter(this@ReikiIndexActivity, fragmentList)

//        viewPager.offscreenPageLimit = 2
        viewPager.adapter = mAdapter
        viewPager.isUserInputEnabled = false

        tv_hire.setOnClickListener {
            tv_hire.setBackgroundResource(R.mipmap.ic_reiki_check)
            tv_whire.setBackgroundResource(R.mipmap.ic_reiki_un_check)
            viewPager.currentItem = 0
        }
        tv_whire.setOnClickListener {
            tv_whire.setBackgroundResource(R.mipmap.ic_reiki_check)
            tv_hire.setBackgroundResource(R.mipmap.ic_reiki_un_check)
            viewPager.currentItem = 1
        }
        initMode()
    }

    private fun initMode() {
        ElvesHttpUtil.getGetInfo(object : JHttpCallback() {
            override fun onSuccess(code: Int, msg: String, info: String) {
                if (code != 200) {
                    ToastUtil.show(msg)
                    return
                }
                var reikindexBean: ReikInfoBean? = GsonUtil.gsonToBean<ReikInfoBean>(info, ReikInfoBean::class.java)
                tv_time_reik.text = reikindexBean?.teamAnima.toString()//我的灵气指数（全）
                tv_my_reik.text = reikindexBean?.baseAnima.toString()
                tv_yqhy.text = reikindexBean?.directHaveAnimaCount +"/"+reikindexBean?.teamCount
                tv_team_total.text = reikindexBean?.teamTotal.toString()
                tv_lqzs.text = reikindexBean?.unionAnima

//                tv_lqzs.text = reikindexBean?.totalTeamRealNameCount


                tv_jqlq.text = reikindexBean?.nearAnima.toString()



            }

        })
    }



    override fun onDestroy() {
        Glide.get(this).clearMemory()
        ElvesHttpUtil.cancel(ElvesHttpConst.POST_OPEN_GET_INFO)
        super.onDestroy()
    }
}


